我有一个MVC 4应用程序,并在表单会话到期时遇到问题,然后用户尝试注销.
防爆.超时设置为5分钟.用户登录.用户10分钟不做任何事情.用户单击LogOff链接.用户收到错误:"提供的防伪令牌适用于用户"XXXX",但当前用户为"".
然后,用户必须通过一些体操来解决这个问题,以便他们可以重新登录然后重新注销(注销正在用于关闭当天的时间卡).
我想我明白为什么会发生这种情况......但不知道如何解决这个问题.
编辑:为什么我认为发生这种情况是因为最初加载页面时,会为当前登录的用户生成AntiForgery令牌.但是当会话到期并且他们尝试导航到注销页面时,当前用户是""而不是实际用户.因此存在不匹配并且呈现错误.
我尝试使用Try Catch块提高我的技能并更好地处理错误.
我有一个执行常见任务的类,在这种情况下检索Facebook AccessToken.如果成功,我想返回AccessToken字符串,如果不是,我想返回错误消息.这些都是字符串,所以没问题.但是当检查代码调用端的返回值时,如何有效地执行此操作?
这就像我需要返回2个值.在成功尝试的情况下,返回= true,"ACESSCODEACXDJGKEIDJ",或者如果失败,则返回= false,"Ooops,出现错误"+ ex.ToString();
然后检查返回值很容易(理论上).我可以想到返回一个true/false返回,然后为字符串设置一个Session变量.
什么是从方法返回多个结果的方法?
在从数据库执行更新模型时,我遇到了EF没有引入外键关系的问题.所以我刚刚删除了.edmx文件并重新生成了它.问题是我的上下文类型被命名为InventoryMgmtContext,现在我收到了错误
The type of namespace InventoryMgmtContext could not be found.
Run Code Online (Sandbox Code Playgroud)
在哪里/如何重命名上下文?
我在我的MVC网络应用程序中运行HangFire,但每当我尝试导航到http:// MyApp/hangfire时,它会将我重定向到我的应用程序的登录页面,就好像我没有登录一样.
我没有明确配置任何授权要求...例如我在web.config中有以下内容,但后来试图让它工作.
<location path="hangfire">
<system.web>
<authorization>
<allow roles="Administrator" />
<deny users="*" />
</authorization>
</system.web>
Run Code Online (Sandbox Code Playgroud)
理论上,这就是我想要的,当我登录我的主Web应用程序时,我将以Administrator角色登录,因此该规则应该有效.
但是,无论我是否在web.config中配置了它,每当我尝试导航到http:// MyApp/hangfire时,它都会将我重定向到我在web.config中配置的应用程序登录页面:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="960" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
当我发布到我的主机时,它不会在我的本地计算机上执行此操作.HangFire是否无法识别我的主应用程序在登录时提供的身份验证Cookie?我一般认为,hangfire应用程序不需要身份验证,那么其他配置可能会认为它有什么作用?
更新1:
我根据hangfire文档添加了授权过滤器,但同样的事情发生了.这是我在Startup.cs中的代码:
using Hangfire;
using Hangfire.Logging;
using Hangfire.Dashboard;
using Hangfire.SqlServer;
using Microsoft.Owin;
using OTIS.Web.AppCode;
using OTISScheduler.AppServ;
using Owin;
using System.Web.Security;
[assembly: OwinStartup(typeof(OTIS.Web.App_Start.Startup))]
namespace OTIS.Web.App_Start
{
public class Startup
{
public void Configuration(IAppBuilder app) {
app.UseHangfire(config => {
config.UseSqlServerStorage("DefaultConnection");
config.UseServer();
//Dashboard authorization
config.UseAuthorizationFilters(new AuthorizationFilter
{
Users = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在登录时设置cookie,并在登录后获取当前用户ID时遇到问题.在下面,intUserId是-1,WebSecurity.IsAuthenticated是false.这不是放置此代码的正确位置吗?在此之后,它会重定向到主页...所以不确定为什么这不是正确的地方.
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
//TODO: set current company and facility based on those this user has access to
int intUserId = WebSecurity.GetUserId(User.Identity.Name);
int intUserId2 = WebSecurity.GetUserId(model.UserName);
UserSessionPreferences.CurrentCompanyId = 1;
UserSessionPreferences.CurrentFacilityId = 1;
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
Run Code Online (Sandbox Code Playgroud) 尝试将orderby语句添加到我的通用存储库方法并获得以下错误.不知道为什么我似乎能够在其他情况下将.OrderBy添加到IQueryable.
我错过了什么?
得到错误:
无法将类型'System.Linq.IOrderedEnumerable'隐式转换为'System.Linq.IQueryable'
代码段(删除了一些部分):
public class QuickbooksRespository<TEntity>
where TEntity : class, Intuit.Ipp.Data.IEntity, new()
{
public virtual IQueryable<TEntity> GetAll(
int page, int pageSize,
Func<TEntity, object> orderbyascending = null,
Func<TEntity, object> orderbydescending = null)
{
int skip = Math.Max(pageSize * (page - 1), 0);
IQueryable<TEntity> results = _qbQueryService
.Select(all => all);
if (orderbyascending != null)
{
results = results.OrderBy(orderbyascending);
}
if (orderbydescending != null)
{
results = results.OrderByDescending(orderbydescending);
}
return results
.Skip(skip)
.Take(pageSize);
}
}
Run Code Online (Sandbox Code Playgroud) 在MVC应用中执行相同实体类型的副本,但希望忽略复制主键(对现有实体进行更新)。但是在下面的映射中将Id列设置为忽略不起作用,并且Id正在被覆盖。
cfg.CreateMap<VendorContact, VendorContact>()
.ForMember(dest => dest.Id, option => option.Ignore())
.ForMember(dest => dest.CreatedById, option => option.Ignore())
.ForMember(dest => dest.CreatedOn, option => option.Ignore())
;
Run Code Online (Sandbox Code Playgroud)
执行地图:
existingStratusVendorContact = Mapper.Map<VendorContact>(vendorContact);
Run Code Online (Sandbox Code Playgroud)
看到了另一个答案,但看来我已经在这样做了。
更新:
仅供参考,我正在Global.asax中创建地图,如下所示:
Mapper.Initialize(cfg =>
{
cfg.CreateMap<VendorContact, VendorContact>()
.ForMember(dest => dest.Id, option => option.Ignore())
.ForMember(dest => dest.CreatedById, option => option.Ignore())
.ForMember(dest => dest.CreatedOn, option => option.Ignore())
;
});
Run Code Online (Sandbox Code Playgroud) 寻找有关使用SDK的v6发布开放图表操作的一些帮助.我已经淘了几天了,找不到任何如何做到这一点的例子.到目前为止,我有:
protected void btnDyno_Click(object sender, EventArgs e)
{
FacebookSDKInterface fbData = new FacebookSDKInterface();
var fb = new FacebookClient(fbData.FacebookAccessToken);
dynamic parameters = new ExpandoObject();
parameters.appnamespace = "thedynoroom";
parameters.action = "added";
parameters.object_name = "dyno_run";
parameters.object_url = "http://thedynoroom.com/DesktopModules/Incite/InciteCore/FBObject.aspx";
try
{
dynamic result = fb.Post("me/", parameters);
lblPostMessageResult.Text = result;
txtMessage.Text = string.Empty;
}
catch (FacebookApiException ex)
{
lblPostMessageResult.Text = ex.Message;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这是不正确的,因为我只是在猜测,因为我无法找到任何关于此的文档.除了http://csharpsdk.org之外还有其他文档吗?
在此先感谢您的帮助!乍得
更新:好的,终于想通了......如果,在你的Facebook开发人员图表仪表板中,你的行动的获取代码链接如下所示:
curl -F 'access_token=blahblahblah' \
-F 'dyno_run=http://samples.ogp.me/266692056752346' \
'https://graph.facebook.com/me/thedynoroom:add'
Run Code Online (Sandbox Code Playgroud)
然后你的代码应该是这样的:
dynamic parameters = new ExpandoObject();
parameters.dyno_run = "http://samples.ogp.me/266692056752346"; …Run Code Online (Sandbox Code Playgroud) 我有一个带有自定义弹出编辑器的 mvc 网格,我想在其中显示日期时间。使用这种类型的绑定时如何格式化日期?
<span type="date" data-format="MM/dd/yyyy" data-bind="text: CreatedOn"></span>
Run Code Online (Sandbox Code Playgroud)
但仍然显示为: Thu Jun 18 2020 12:43:48 GMT-0500 (Central Daylight Time)
c# ×5
asp.net-mvc ×4
android ×1
automapper ×1
cordova ×1
hangfire ×1
kendo-grid ×1
linq ×1
return ×1