我花了一些时间搜索并找到了很多令人困惑的答案,所以我会在这里发帖澄清.
我正在使用MVC4 VS2012使用域身份验证创建了一个Intranet站点.一切正常.但是,要管理有权访问此Web应用程序不同区域的用户,我不希望使用无法管理的AD组,也不能使用Web应用程序的用户.
还有其他选择吗?我假设这将涉及关联/存储属于自定义角色的域名,并使用Authorize属性来控制访问.
[Authorize(Roles = "Managers")]
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议最好的模式或指向我正确的方向?
我看到了一个类似的解决方案链接,但我仍然不确定如何对存储的角色列表使用它,并根据这些角色验证用户.任何人都可以详细说明这个解决方案是否有效
protected void Application_AuthenticateRequest(object sender, EventArgs args)
{
if (HttpContext.Current != null)
{
String[] roles = GetRolesFromSomeDataTable(HttpContext.Current.User.Identity.Name);
GenericPrincipal principal = new GenericPrincipal(HttpContext.Current.User.Identity, roles);
Thread.CurrentPrincipal = HttpContext.Current.User = principal;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个MVC4页面,其中包含一个表单,其中包含一组复选框,单选按钮和用作搜索字段的文本框.在发布后,将解析选择,并使用新结果更新下部结果网格.现在,所有表单值在返回时都被清除,新结果显示在网格中 - 只有网格是模型的一部分.
我希望所有表单选择在发布后保留其值,以便用户可以查看(和更改)下一个帖子/搜索的选择.表格上印有viewbags.
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "searchform" }))
{
@Html.ValidationSummary("Please correct the following errors")
<div style="float:left;">
<div style="float:left;">
<label>Name:</label>
@Html.TextBox("name")
</div>
<div style="float:left; margin-left:15px">
<label>Company:</label>
@Html.TextBox("company")
</div>
<div style="float:left; margin-left:65px">
<label>Date Range:</label>
@Html.TextBox("dateStart", "", new { @class = "datefield", type = "date" })
to
@Html.TextBox("dateEnd", "", new { @class = "datefield", type = "date" })
</div>
</div>
<div style="clear: both;">
Match Any Categories? <input type="radio" name="categoryMatchAll" value="false" checked="checked" />
Match All Categories? <input type="radio" …Run Code Online (Sandbox Code Playgroud) 我试图在这里关注一些好的帖子以使其工作,但每次我点击ajax回发时,我的控制器中的断点显示一个具有空值的模型.此页面显示仅供查看的模型值,但我尝试将它们放在自己的表单中,并将它们包装在ajax表单中,似乎没有任何效果.
@model VendorProfileIntranet.Models.VendorProfile
$(function () {
$("form").submit(function () {
if ($(this).valid()) {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (result) {
$("#message").html(result);
}
});
}
return false;
});
Run Code Online (Sandbox Code Playgroud)
});
@using (Ajax.BeginForm("SelectVendor", "Home", new AjaxOptions { HttpMethod="post", InsertionMode=InsertionMode.Replace, UpdateTargetId="message" }))
{
<div style="float:right; width:500px">
<div id="message"></div>
<input id="btnSubmit" type="submit" value="Select Vendor" />
</div>
Run Code Online (Sandbox Code Playgroud)
该视图非常长(仅显示用于查看的模型值),此处缩写.
<div id="viewform">
<div id="viewform-contact" style="float:left;">
<fieldset>
<legend>Contact Information</legend>
@Html.HiddenFor(model => model.ProfileID)
<div class="view-field">
@Html.LabelFor(model => model.Name)
@Html.DisplayFor(model => model.Name)
</div>
<br />
<div …Run Code Online (Sandbox Code Playgroud)