带有Guid的MVC QueryString返回404 [英] MVC QueryString with Guid returns 404
问题描述
我的开发服务器上有问题.... 在我的本地计算机上,一切正常....
I have a problem on my Development server.... On my local machine everything works....
这是问题所在
我有一个看起来像这样的页面:
I have a Page that looks like this:
@using Skipstone.Web;
@using Skipstone.Web.Providers;
@using Skipstone.Web.Extensions
@{
string id = (Request.QueryString["id"] == null) ? ProfileProvider.CurrentUser().UserId : Request.QueryString["id"];
Profile user = new Profile(id);
ViewBag.Title = "Profile - " + user.Surname + ", " + user.Forename;
string credentialId = (user.CredentialId != null && user.CredentialId != "") ? user.CredentialId : "Credential Id";
}
@if (id != null) {
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<div class="container">
<div class="row">
<div class="sixcol">
<div class="profile">
@if (!string.IsNullOrEmpty(user.Photo))
{
<img src="@user.Photo" />
}
else
{
<img src="/Content/media/user.png" />
}
<h2>@user.Forename @user.Surname</h2>
<h3>@user.JobTitle</h3>
<p>@HtmlExtensions.decodeEscapedText(user.Bio)</p>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="sixcol">
<div class="message"></div>
</div>
<div class="sixcol">
</div>
</div>
</div>
<div class="container" id="profile-view">
<div class="row">
<div class="sixcol">
<div class="profile form">
@if (id == ProfileProvider.CurrentUser().UserId)
{
<a href="#" class="button edit small" style="float: right;">Edit</a>
}
<ul>
@if (user.Telephone != null && user.Telephone != "")
{ <li class="profile-tel"><span class="icon"></span><span>@user.Telephone</span></li> }
@if (user.Mobile != null && user.Mobile != "")
{ <li class="profile-mob"><span class="icon"></span><span>@user.Mobile</span></li> }
@if (user.Email != null && user.Email != "")
{ <li class="profile-email"><span class="icon"></span><span><a href="mailto:@user.Email">@user.Email</a></span></li> }
</ul>
<ul>
@if (user.Twitter != null && user.Twitter != "")
{ <li class="profile-twitter"><span class="icon"></span><span><a href="mailto:@user.Twitter">@user.Twitter</a></span></li> }
@if (user.Facebook != null && user.Facebook != "")
{ <li class="profile-facebook"><span class="icon"></span><span><a href="mailto:@user.Facebook">@user.Facebook</a></span></li> }
@if (user.LinkedIn != null && user.LinkedIn != "")
{ <li class="profile-linked"><span class="icon"></span><span><a href="mailto:@user.LinkedIn">@user.LinkedIn</a></span></li> }
</ul>
</div>
</div>
<div class="sixcol"></div>
</div>
</div>
<form id="profile-edit" style="display: none;">
<div class="container">
<div class="row">
<div class="sixcol">
<div class="form form-top form-bottom">
<input type="hidden" id="UserId" name="UserId" value="@user.UserId" />
<input type="hidden" id="CompanyName" name="CompanyName" value="@user.CompanyName" />
<input type="hidden" id="Photo" name="Photo" value="@user.Photo" />
<input type="hidden" id="UserCanEdit" name="UserCanEdit" value="@user.UserCanEdit" />
<input type="hidden" id="UserCanEditOwn" name="UserCanEditOwn" value="@user.UserCanEditOwn" />
<input type="hidden" id="UserCanApprove" name="UserCanApprove" value="@user.UserCanApprove" />
<input type="hidden" id="UserRequiresApproval" name="UserRequiresApproval" value="@user.UserRequiresApproval" />
<label class="block-label" for="Title">Title</label>
<div class="textbox"><input type="text" class="required" name="Title" id="Title" value="@user.Title" /></div>
<label class="block-label" for="Forname">Forname(s)</label>
<div class="textbox"><input type="text" class="required" name="Forename" id="Forename" value="@user.Forename" /></div>
<label class="block-label" for="Surname">Surname</label>
<div class="textbox"><input type="text" class="required" name="Surname" id="Surname" value="@user.Surname" /></div>
<label class="block-label" for="UserName">Username</label>
<div class="textbox"><input type="text" class="required" id="UserName" name="UserName" value="@user.UserName" /></div>
<label class="block-label" for="file">Upload profile image</label>
<div class="textbox file"><input type="file" id="file" name="file" /></div>
<label class="block-label" for="JobTitle">Job title</label>
<div class="textbox"><input type="text" name="JobTitle" id="JobTitle" value="@user.JobTitle" /></div>
<label class="block-label" for="Telephone">Telephone</label>
<div class="textbox"><input type="text" name="Telephone" id="Telephone" value="@user.Telephone" /></div>
<label class="block-label" for="Mobile">Mobile</label>
<div class="textbox"><input type="text" name="Mobile" id="Mobile" value="@user.Mobile" /></div>
<label class="block-label" for="Email">Email address</label>
<div class="textbox"><input type="text" class="required" name="Email" id="Email" value="@user.Email" /></div>
@if (SettingsProvider.CurrentSiteSettings().TwoFactorAuthentication)
{
<label class="block-label" for="CredentialId">Credential Id</label>
<div class="textbox"><input type="text" class="required" id="CredentialId" name="CredentialId" value="@user.CredentialId" /></div>
<input type="hidden" class="required" name="Code" value="Security Code" />
}
else
{
<input type="hidden" class="required" name="CredentialId" value="@credentialId" />
<input type="hidden" class="required" name="Code" value="Security Code" />
}
<label class="block-label" for="LinkedIn">LinkedIn</label>
<div class="textbox"><input type="text" name="LinkedIn" id="LinkedIn" value="@user.LinkedIn" /></div>
<label class="block-label" for="Twitter">Twitter</label>
<div class="textbox"><input type="text" name="Twitter" id="Twitter" value="@user.Twitter" /></div>
<label class="block-label" for="Facebook">Facebook</label>
<div class="textbox"><input type="text" name="Facebook" id="Facebook" value="@user.Facebook" /></div>
<label class="block-label" for="Bio">Bio</label>
<div class="textbox"><textarea id="Bio" name="Bio" rows="9">@user.Bio</textarea></div>
<div class="action">
<button>Save</button>
</div>
<button id="cancel">Cancel</button>
</div>
</div>
</div>
</div>
</form>
<script src="@Url.Content("~/Scripts/jquery.skipstone-profile-save.js")" type="text/javascript"></script>
}
else
{
throw new Exception("Invalid id specified.");
}
现在,我遇到了一个问题....
Now, I am getting an issue....
/个人资料(显示当前用户的字段并可以正常工作)
/Profile (Show the fields for the current user and works fine)
/Profile?id = 4(状态Guid应包含32个数字和4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx))
/Profile?id=4 (states Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx))
/Profile?id = E23CB58D-BDBC-4BE5-A27C-7E6518ED72B0(显示404错误...)
/Profile?id=E23CB58D-BDBC-4BE5-A27C-7E6518ED72B0 (Displays 404 error...)
我不知道为什么Guid不能工作. 就像我说过的那样,这在我的本地计算机上有效,但在开发服务器上则无效. 我应该指出,没有任何页面可以接受guid字符串,它们都和个人资料"页面一样....
I have no idea why the Guid one will not work. Like I have said, this works on my local machine, but doesn't work on the Development server. I should point out that no page that accepts a guid string works, they all do the same as the Profile page....
有人知道为什么会这样吗?
Does anyone know why this might be happening?
更新
我已将代码更改为
@{
string id = Request.QueryString["id"];
}
@id
我仍然遇到问题
更新2
我将代码更改为此:
@{
string id = (Request.QueryString["UserId"] == null) ? ProfileProvider.CurrentUser().UserId : Convert.ToString(Request.QueryString["UserId"]);
Profile user = new Profile(id);
ViewBag.Title = "Profile - " + user.Surname + ", " + user.Forename;
string credentialId = (user.CredentialId != null && user.CredentialId != "") ? user.CredentialId : "Credential Id";
}
因为我认为尝试使用Id/id作为参数可能是一个问题.无论如何,我仍然遇到同样的问题....
because I figured it might be an issue with trying to use Id/id as the parameter. Anyway, I still get the same problem....
推荐答案
我知道了. 正因为如此,在Web.config
I figured it out. It was because of this in the Web.config
<requestLimits maxAllowedContentLength="1048576000" maxUrl="260" maxQueryString="25" />
这是maxQueryString.
It was the maxQueryString.
此后,我同时删除了maxUrl和maxQueryString,现在都可以正常使用了:)
I have since removed both maxUrl and maxQueryString and it is all working now :)
这篇关于带有Guid的MVC QueryString返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!