Error: Could not find 'protectedBrowserStorage.get' ('protectedBrowserStorage' was undefined).

warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect.
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: Could not find 'protectedBrowserStorage.get' ('protectedBrowserStorage' was undefined).
Error: Could not find 'protectedBrowserStorage.get' ('protectedBrowserStorage' was undefined).
    at http://localhost:5000/_framework/blazor.server.js:1:497
    at Array.forEach (<anonymous>)
    at i.findFunction (http://localhost:5000/_framework/blazor.server.js:1:465)
    at E (http://localhost:5000/_framework/blazor.server.js:1:2606)
    at http://localhost:5000/_framework/blazor.server.js:1:3494
    at new Promise (<anonymous>)
    at kt.beginInvokeJSFromDotNet (http://localhost:5000/_framework/blazor.server.js:1:3475)
    at http://localhost:5000/_framework/blazor.server.js:1:72077
    at Array.forEach (<anonymous>)
    at kt._invokeClientMethod (http://localhost:5000/_framework/blazor.server.js:1:72063)
      Microsoft.JSInterop.JSException: Could not find 'protectedBrowserStorage.get' ('protectedBrowserStorage' was undefined).

 

 at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
         at Microsoft.AspNetCore.ProtectedBrowserStorage.ProtectedBrowserStorage.GetAsync[T](String purpose, String key)
         at Ticketing.Web.Services.UserService.GetUserSession() in
         at Ticketing.Web.Services.UserService.GetAuthenticationStateAsync() in 
         at Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync()
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'Xz3BBSByaV8JWhu-LWpu6zW20FFjq2ofYDfFhxk06cw'.
      Microsoft.JSInterop.JSException: Could not find 'protectedBrowserStorage.get' ('protectedBrowserStorage' was undefined).

 

这个浏览器F12查看后台请求,发现有一堆js文件没有加载。

而这些文件,在项目路径\wwwroot\lib下。所以,需要publish站点,再运行exe。

 

 

When deploying an ASP.NET Core application to IIS, there are two common deployment models: IIS Site and IIS Application. The behavior you described, where the JS files are found under the wwwroot/js folder when deployed as an IIS Site but not as an IIS Application, can be explained by the way IIS handles static file serving in these deployment models.

  1. IIS Site Deployment: In this model, the ASP.NET Core application is deployed as a standalone website in IIS. The root folder of the website is set to the wwwroot folder of the application. When a request for a static file like a JS file is received, IIS looks for the file in the configured root folder (i.e., wwwroot/js) and serves it directly. This is the recommended deployment model for ASP.NET Core applications.

  2. IIS Application Deployment: In this model, the ASP.NET Core application is deployed as an application within an existing website in IIS. The application is typically mapped to a subdirectory or a virtual directory within the website. When a request for a static file is received, IIS processes the request based on the application's configuration. By default, it does not serve static files from the application's root folder (wwwroot) directly. Instead, it passes the request to the ASP.NET Core runtime, which handles static file serving based on the configuration in Startup.cs. This adds some additional overhead and configuration complexity compared to the IIS Site deployment model.

If you are experiencing issues with the IIS Application deployment model not finding the JS files in the wwwroot/js folder, it could be due to misconfiguration or a difference in how static files are being served. You may need to adjust the configuration in your Startup.cs file to ensure that static files are correctly handled and served by the ASP.NET Core runtime.

To troubleshoot the issue, you can check the following:

  • Ensure the UseStaticFiles middleware is properly configured in your Startup.cs file:

    csharp
  • app.UseStaticFiles();
  • Verify the file path references in your HTML or Razor views. Make sure they are correctly relative to the application's root URL, considering any subdirectory or virtual directory mappings.

  • Check the application's configuration in IIS to ensure it is correctly mapped to the appropriate physical path and that the necessary permissions are set.

By addressing these factors, you should be able to resolve the issue and successfully serve the JS files under the wwwroot/js folder in an IIS Application deployment.

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(187)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-12-07 cookie groups
2021-12-07 Client-Side Cookie Management optanon-category-C0004
2021-12-07 OneTrust Cookie Auto-Blocking™
2021-12-07 The Auto Block, blocks my pictures on my website OneTrust
2021-12-07 System.Xml.XmlException: There is no Unicode byte order mark. Cannot switch to Unicode.
2017-12-07 kentico中自定义错误页面
2017-12-07 Troubleshooting Failed Requests Using Tracing in IIS 8.5
点击右上角即可分享
微信分享提示