我有一个用户个人帐户的.NET Web API项目.我可以使用标准模板AccountController注册用户.但是,我现在想要根据用户类型设置角色并将用户添加到角色.
DB中没有自动设置角色.如何设置角色以及如何将用户添加到角色?
我可以在此找到的唯一信息是基于旧的ASP.NET成员资格,因此未能为其设置存储过程.
已经在MSDN上搜索了论坛和教程,似乎无法找到Web API的示例.
我正在尝试更新从数据库中检索的DataTable,然后再将其绑定到Gridview.
但是,当我更新小数字段时,小数点后的部分归零.我错过了什么?
if (HttpContext.Current.Request.IsAuthenticated)
{
// Get additional price matches
using (SqlConnection stockConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString))
{
// Check for trade match offer
SqlCommand tradePCCheck = new SqlCommand("getAllMyPriceMatches", stockConn);
tradePCCheck.CommandType = CommandType.StoredProcedure;
SqlParameter email = tradePCCheck.Parameters.Add("@email", SqlDbType.NVarChar);
try
{
email.Value = this.Context.User.Identity.Name;
}
catch
{
email.Value = " ";
}
SqlParameter thedate = tradePCCheck.Parameters.Add("@theDate", SqlDbType.DateTime);
thedate.Value = DateTime.Now.AddHours(-50);
stockConn.Open();
SqlDataReader pcReader = tradePCCheck.ExecuteReader();
pms.Load(pcReader);
pcReader.Close();
stockConn.Close();
}
}
//Set Connection, Open the DB & Fill Data Set
using (SqlConnection stockConn …Run Code Online (Sandbox Code Playgroud) 我有一个问题,骨干PUT请求返回405(方法不允许).发生这种情况是因为代码中的model.save()没有发送到具有模型ID的模型URL.
这是PUT.
Remote Address:::1:670
Request URL:http://localhost:670/api/contacts
Request Method:PUT
Status Code:405 Method Not Allowed
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Authorization:Bearer YLPwKSpBsBrFUemRHdjz....
Connection:keep-alive
Content-Length:417
Content-Type:application/json
Host:localhost:670
Origin:http://localhost:660
Referer:http://localhost:660/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Request Payloadview source
{id:1, ContactOrganisation:Cow on a Mission, ContactPerson:Ben Drury, Phone:07980567574,…}
Address: "----"
ContactOrganisation: "----"
ContactPerson: "Ben"
CreatedBy: "----"
CreatedOn: "2014-03-03T16:40:50.037"
Description: "----"
Email: "---"
Organistion: "----"
Phone: "----"
Website: "http://www.cogiva.com"
id: 1
Response Headersview source
Access-Control-Allow-Headers:Authorization, Content-Type
Access-Control-Allow-Methods:GET, …Run Code Online (Sandbox Code Playgroud) 我在更新面板中使用GridView.我有gridview生成的编辑和取消按钮.
我第一次单击编辑时,gridview编辑模板显示正常.然后,如果我单击取消,或在另一行编辑,则没有任何反应.似乎更新面板已停止工作.
如果我在没有更新面板的情况下做同样的事情,回发工作正常,gridview会做它应该做的事情(尽管它刷新整个页面非常麻烦,这就是我想使用updatepanel的原因!)
<asp:UpdatePanel ID="upSentOrders" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvSentOrders" runat="server"
autogeneratecolumns="False"
allowpaging="false"
DataKeyNames="titxn_id"
AlternatingRowStyle-CssClass="gvAlternate"
CssClass="gvTable"
OnRowDataBound="addSentTotals"
OnRowEditing="editOrder"
OnRowCancelingEdit="cancelEdit"
OnDataBound="showSentTotals"
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="false"
ShowFooter="true"
ShowHeader="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<table class="basketHeader">
<tr>
<td class="basketTitle"><asp:Label ID="lblTitle" runat="server" Text="Order Date" /></td>
<td class="basketPX"><asp:Label ID="lblPXOffer" runat="server" Text="Part Ex" /></td>
<td class="basketCash"><asp:Label ID="lblCashOffer" runat="server" Text="Cash" /></td>
<td class="basketDelete"> </td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table class="basket">
<tr>
<td class="basketTitle"><asp:Label ID="lblTitle" runat="server" Text='<%# String.Format("{0:dd MMMM yyyy}", Eval("titxn_date")) %>' /></td>
<td class="basketPX"><asp:Label ID="lblPXOfferItem" runat="server" Text='<%# "£" + Eval("titxn_totalpxatsend") %>' /></td> …Run Code Online (Sandbox Code Playgroud) 我有一个角度服务来管理我的屏幕警报:
angular.module('theapp')
.factory('Alerts', function ($timeout) {
var unsetMsg = null;
return {
alertType: null,
alertTitle: null,
alertMessage: null,
setMessage: function(type, title, message, timed) {
var self = this;
$timeout.cancel(unsetMsg);
self.alertType = type;
self.alertTitle = title;
self.alertMessage = message;
if (timed)
{
unsetMsg = $timeout(self.unsetMessage,5000);
}
},
unsetMessage: function() {
this.alertType = null;
this.alertTitle = null;
this.alertMessage = null;
$timeout.cancel(unsetMsg);
}
}
});
Run Code Online (Sandbox Code Playgroud)
设置消息正常工作(从角度控制器调用)并设置超时变量OK,但是当超时(unsetMessage)内调用的函数在5秒延迟后运行时,代码会抛出错误this is undefined.为什么它不会将自己视为一个对象,我如何实现我想要做的事情?
我在AJAX工具包的AsyncFileUpload的uploadError javascript函数中有以下内容:
function uploadError(sender, args) {
document.getElementById("<%# uploadResult.ClientID %>").innerText = args.get_fileName(), "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,ClientID调用返回Null,因此javascript错误.
我还注意到,一旦页面加载,我的控件都没有通常的.NET格式:EG:
<asp:Label runat="server" Text="Select an image to upload it to this stock item...." ID="uploadResult" />
Run Code Online (Sandbox Code Playgroud)
通常会像这样呈现:
<span id="ctl00_ContentPlaceHolder1_uploadResult">Choose a webstock file to upload...</span>
Run Code Online (Sandbox Code Playgroud)
但是使用这个文件它呈现为:
<span id="uploadResult">Select an image to upload it to this stock item....</span>
Run Code Online (Sandbox Code Playgroud)
我认为这是同一个问题,但不知道为什么会发生这种情况.
我正在编写一个主干(带有require)应用程序,需要搜索一个集合来拉出第一个模型(我使用一个唯一的id,所以只有一个).
我遇到的问题是我收到了一个错误:
Uncaught TypeError: Object [object Object] has no method 'findWhere'
Run Code Online (Sandbox Code Playgroud)
当它使用findWhere命令到达该行时.
视图初始化是:
initialize: function (models) {
this.locationCollection = new LocationCollection();
this.locationCollection.fetch();
this.render();
},
Run Code Online (Sandbox Code Playgroud)
然后我在另一个方法中访问locationCollection,该方法的第一行是发生错误的地方:
createCrate: function (eventname) {
var setLocationList = this.locationCollection.findWhere({ Name: $('#location').val() });
console.log($('#location').val());
console.log(setLocationList);
},
Run Code Online (Sandbox Code Playgroud)
这是LocationCollection的声明代码:
define([
'jquery',
'underscore',
'backbone',
'model/LocationModel'
], function ($, _, Backbone, LocationModel) {
var LocationCollection = Backbone.Collection.extend({
model: LocationModel,
url: "/api/locations"
});
return LocationCollection;
});
Run Code Online (Sandbox Code Playgroud)
我可以访问视图中其他位置的this.localCollection中的项目,并将它们输出到主干类型扩展中,因此已经填充了该集合.
知道为什么这个系列不能调用findWhere吗?
asp.net ×3
backbone.js ×2
ajax ×1
angularjs ×1
api ×1
c# ×1
clientid ×1
collections ×1
datarow ×1
datatable ×1
gridview ×1
javascript ×1
put ×1
roles ×1
service ×1
this ×1
updatepanel ×1