我在ASP.NET中成功实现了基于角色的授权.当一个人没有所需的角色时,他会看到401.2未经授权的错误页面.
我现在想要完成的是在我的应用程序中有一个自定义的401页面,并通过web.config中的设置将其重定向到那里.我试过这个:
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="401" redirect="NoAccess.htm" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
但这并没有被抓住.我是否必须在IIS中覆盖它?我希望不会因为这会使事情更难部署.
参考文献:http://developer.android.com/google/gcm/demo.html
尝试向我的Android设备发送消息时的服务器401.
HTTP Status 500 - HTTP Status Code: 401
type Exception report
message HTTP Status Code: 401
description The server encountered an internal error (HTTP Status Code: 401) that prevented it from fulfilling this request.
exception
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
com.google.android.gcm.server.Sender.send(Sender.java:121)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServ let.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.
Run Code Online (Sandbox Code Playgroud)
谁能告诉我怎么解决?谢谢!
我有一个使用 Spring Boot 和 Spring Security 的项目。Spring Security 使用每个请求的会话 ID 验证标头。如果会话 ID 无效或过期,将返回错误代码 401。会话 ID 在到达控制器之前经过验证。
现在,我面临一个问题,如果用户输入无效的 URL 而没有有效的会话 ID,响应代码仍然是 401,因为会话 ID 首先经过验证。我的期望是,如果 URL 无效,将返回错误代码 404(未找到 HTTP 请求的映射)。换句话说,我想在验证会话 ID 之前验证 URL。
有什么办法可以做到这一点,因为标头中的会话 ID 在到达控制器之前已在 GenericFilterBean 中进行了验证?
任何帮助表示赞赏。谢谢。
java spring http-status-code-404 http-status-code-401 spring-boot
我一直在努力让我的jquery调用webmethod工作.我被服务器以"401 Unauthorized"响应退回.我必须在web.config或其他阻止成功调用的地方设置不正确.
非常感谢您的见解!
button.OnClickAction = "PageMethod('TestWithParams', ['a', 'value', 'b', 2], 'AjaxSucceeded', 'AjaxFailed'); return false;";
Run Code Online (Sandbox Code Playgroud)
function PageMethod(fn, paramArray, successFn, errorFn) {
var pagePath = window.location.pathname;
var urlPath = pagePath + "/" + fn;
//Create list of parameters in the form:
//{"paramName1":"paramValue1","paramName2":"paramValue2"}
var paramList = '';
if (paramArray.length > 0) {
for (var i = 0; i < paramArray.length; i += 2) {
if (paramList.length > 0) paramList += ',';
paramList += '"' + paramArray[i] + '":"' + paramArray[i + …Run Code Online (Sandbox Code Playgroud) asp.net authentication jquery webmethod http-status-code-401
我使用Asp.net,IIS 6和cdn来提供图像.我在网站上加载图片时遇到问题.图像位于虚拟文件夹下.每次我点击浏览器刷新时,一些图像会给出401未经授权的错误.(显示的图像和显示401错误的图像数量在每次刷新时都不同.)我很难解决这个问题.任何帮助都会受到很多欢迎.
亲切的问候.
PS:我还使用负载均衡器在两台服务器之间分配流量.其中一个服务器具有实际文件和虚拟文件夹.另一台服务器有虚拟文件夹,显示有文件的服务器的路径和IP.我尝试通过每个服务器使用网站,但他们都有同样的问题.
这是标题;
响应:
HTTP/1.1 401 Unauthorized
Content-Length: 1608
Content-Type: text/html
Server: Microsoft-IIS/6.0
Date: Thu, 28 Apr 2011 14:38:55 GMT
Run Code Online (Sandbox Code Playgroud)
请求
GET /img/blog/2011%2f4%2f4.png HTTP/1.1
Host: cdn.***.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16 ( .NET CLR 3.5.30729)
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://www.***.com/Blog
Run Code Online (Sandbox Code Playgroud) 我们正在开发一个WCF REST Web服务,它只接收来自任何匿名用户的大量任意文本,然后在后端执行一些处理.
例如,这是我们的Web服务中的一种方法:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyRESTService : IMyRESTService
{
[WebInvoke(Method = "PUT", UriTemplate = "/MyRESTMethod?paramA={paramA}¶mB={paramB}")]
public Stream MyRESTMethod(string paramA, string paramB, Stream rawData)
{
//do some stuff...
}
}
Run Code Online (Sandbox Code Playgroud)
如果我们只使用默认的IIS设置,我们得到一个(401) Unauthorized.然而,在经过多次反复试验后,我们发现我们可以通过在实际.svc文件上为我们的服务提供WRITE访问权限来使其工作.
我的问题是:为什么IIS需要对.svc文件进行WRITE访问以使其工作?有没有更好的方法,还是我坚持这种hackish(可能不安全)的解决方法?
WTF微软?
可能相关:
Chrome会在http:// user:pass@path.to/image的静脉中为基本身份验证的IMG-urls引发401限制错误,但之前没有使用相同的资源和代码执行此操作.直接调用时,如"在新选项卡中打开",图像加载顺利.我很困惑.有任何想法吗?
我正在运行以下程序.但我得到以下错误消息.401****401****(继续重复)
代码(来自某个论坛)基本上尝试连接到Twitter并获取推文.当它在ubuntu终端上运行时,会出现401错误消息.
import sys
import json
import pymongo
import tweepy
consumer_key="XX" ##all the keys and codes have to be strings
consumer_secret="XX"
access_token = "XX"
access_token_secret = "XX"
# This is the listener, resposible for receiving data
class StdOutListener(tweepy.StreamListener):
def on_data(self, data):
# Twitter returns data in JSON format - we need to decode it first
decoded = json.loads(data)
# Also, we convert UTF-8 to ASCII ignoring all bad characters sent by users
print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore'))
print …Run Code Online (Sandbox Code Playgroud) 我有一个在需要使用JQuery $ .ajax方法(目前使用jquery 1.7.2)的网页上运行的脚本向不同域上的服务端点提交几个GET请求.我在IE(9,10,11)中使用了ajax调用,但它在Firefox和Chrome中失败了401 Unauthorized响应.Chrome中的部分其他错误消息是"访问此资源需要完全身份验证".
我的ajax调用设置如下(对于这些失败的请求,dataType为"json",async为true):
$.ajax({
url: url,
type: "GET",
async: isAsync,
dataType: dataType,
username: user,
password: pswd,
success: function (response, status) {
// success code here
},
failure: function (response, status) {
// failure code here
},
complete: function (xhr, status) {
// on complete code here
}
});
Run Code Online (Sandbox Code Playgroud)
我传递了访问该服务所需的用户名和密码,这在IE中有效.我理解JQuery ajax函数将正确处理身份验证,因此如果响应返回指示需要授权,它将使用提供的凭据来正确地生成该请求.我在这里错过了什么吗?我是否需要手动添加Authorization标头才能生效?
更新:以下是Chrome和IE通过F12调试工具报告的请求,响应和Cookie信息(某些信息已替换为[...已删除...])
铬(42.0.2311.90米)
响应标题
access-control-allow-credentials:true access-control-allow-origin:[... removed ...] access-control-expose-headers:cache-control:private,max-age = 0,must-revalidate connection :keep-alive content-encoding:gzip content-length:296 content-type:text/html; charset = ISO-8859-1 date:Tue,21 Apr 2015 20:55:12 GMT expires:Tue,2015年4月21日20 :55:12 GMT p3p:CP …
当我尝试连接到未经授权的网址时,我会进入Chrome:
zone.js:1274 POST http://localhost:8080/rest/v1/runs 401 (Unauthorized)
core.umd.js:3462 EXCEPTION: Response with status: 401 Unauthorized for URL: http://localhost:8080/rest/v1/runs
Run Code Online (Sandbox Code Playgroud)
我的Home Component的代码是:
import {Component, OnInit} from '@angular/core';
import {Run} from "../_models/run";
import {Http, Response} from "@angular/http";
import {RunService} from "../_services/run.service";
import {Observable} from "rxjs";
@Component({
moduleId: module.id,
templateUrl: 'home.component.html'
})
export class HomeComponent implements OnInit{
url: "http://localhost:8080/rest/v1/runs"
username: string;
runs: Run[];
constructor(private http: Http, private runService: RunService) {
}
ngOnInit(): void {
this.username = JSON.parse(localStorage.getItem("currentUser")).username;
this.runService.getRuns()
.subscribe(runs => {
this.runs = runs;
});
} …Run Code Online (Sandbox Code Playgroud)