Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Serer打包部署后会出现定位的那个js 404,并且主页面显示的时间不对 #12

Open
Hdurian-CH opened this issue Jul 19, 2023 · 12 comments

Comments

@Hdurian-CH
Copy link

No description provided.

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 19, 2023

可以提供更详细的信息吗,我这边尝试了一下,似乎没有问题

@Hdurian-CH
Copy link
Author

Hdurian-CH commented Jul 19, 2023

打包发布之后用浏览器打开部署的域名,主页面报空引用异常,控制台显示/wwwroot/_content/Darnton.Blazor.DeviceInterop/js/geolocation.js资源404

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 19, 2023

打包后的路径里wwwroot_content\Darnton.Blazor.DeviceInterop\js,把Geolocation.js换成小写试试。

@Hdurian-CH
Copy link
Author

我试过改小写了,还是不行

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 19, 2023

模仿maui那个项目,复制粘贴一个GeolocationService.cs,把它作为依赖注入。
builder.Services.AddScoped<IGeolocationService, YourWeather.Server.Services.GeolocationService>();

@Hdurian-CH
Copy link
Author

我发现还有个问题,server打包之后拿不到那个location.json,得把Rcl里面的location.json复制到server的root下,不然addlocation页面就报错了

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 19, 2023

确实有这个问题,之前没有打包过Server,在Debug中是没问题的,我想想办法

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 19, 2023

#if DEBUG
            var uri = $"{AppContext.BaseDirectory}/wwwroot/{baseUri}";
#else
            var uri = $"{AppContext.BaseDirectory}/wwwroot/_content/YourWeather.Rcl/{baseUri}";
#endif

这么写就可以,或者判断第一个路径是否存在,如果不存在就用第二个。
我更新了一下,把读取json文件的方法抽离了出来。

@Hdurian-CH
Copy link
Author

想请教以下,就以这个weather项目,server模式下在天气页面不断刷新,内存一直都在涨怎么解决

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 21, 2023

server模式每一次刷新都是建立一个新的连接,这个连接是需要服务端维护的,所以内存涨是正常的。

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 21, 2023

Server模式我用的不多,可能理解不到位。

@Yu-Core
Copy link
Owner

Yu-Core commented Jul 21, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants