使用Authentication驗證表單頁時會需要在Webconfig中加入以下code
<authentication mode="Forms">
<forms loginUrl="View/Login.aspx"
protection="All"
timeout="30"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="View/Index.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
在網路上找到的答案通常是這樣
http://stackoverflow.com/questions/20032240/authentication-failed-during-call-webmethod-from-jquery-ajx-with-aspnet-friendly
In your App_Start folder, within your RouteConfig....Comment out the following line or change it's RedirectMode://settings.AutoRedirectMode = RedirectMode.Permanent;
但是我開的專案是empty website,打開以後什麼都沒有的專案
這時就有這兩個方式
1. 透過修改authorization
將 <deny users="?" /> 改成 <allow users="*" />
2. 修改jQuery Ajax url
From: 'userForm.aspx/getAllUsers'
To: '<%= ResolveUrl("userForm.aspx/getAllUsers") %>'
終於解決
參考
https://forums.asp.net/t/1975897.aspx?jquery+ajax+calls+to+asp+net+web+methods+authentication+error+
沒有留言:
張貼留言