小编Dev*_*per的帖子

如何在C#中的日期范围内获取所有周末

我只是想知道是否有一个简单的方法或框架来使C#中的日期范围内的所有周末?

是否也可以使用LINQ?

任何线索?

谢谢!

.net c# date-range dayofweek weekend

2
推荐指数
2
解决办法
8716
查看次数

是否在ASP.NET标识中不推荐使用Session.SessionTimeout

看起来以下代码在ASP.NET身份中不再起作用了?它是否正确?

Global.asax中

protected void Session_Start(object sender, EventArgs e)
{
    Session.Timeout = 5; // It has no impact to Session
}
Run Code Online (Sandbox Code Playgroud)

此代码仅定义会话超时.

STARTUP.AUTH.CS

public void ConfigureAuth(IAppBuilder app)
{            
    var sessionTimeout = 20; // 

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        ExpireTimeSpan = TimeSpan.FromMinutes(sessionTimeout),
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        CookieName = ".MyApp1_Authentication",
        SlidingExpiration = true
    });
}
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc session-timeout global-asax asp.net-mvc-5 asp.net-identity

2
推荐指数
1
解决办法
3381
查看次数

如何从C#中的特定资源文件中获取字符串资源

在我们项目中的某些情况下,我们必须忽略当前的应用程序文化并获取英语资源。

基本上,我们对所有语言都这样做

<label>@ModelEntities.Properties.Resource.Gender</label>
Run Code Online (Sandbox Code Playgroud)

怎么可能只用英语?

我假设我们以某种方式创建了一些对Resource.resx?

我用过了

 ResourceManager rm = new ResourceManager("Resource.Strings",
                     Assembly.GetAssembly(typeof(ModelEntities.Properties.Resource))); 
  var s = rm.GetString("Age");
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用。

谢谢!

.net c# asp.net-mvc localization

2
推荐指数
3
解决办法
1万
查看次数

ASP.NET Identity用户名中的特殊语言字符

我想ø在用户名中使用一些特殊字符.

但我正面临着这个错误

IdentityResult result = UserManager.Create(applicationUser, password);
Run Code Online (Sandbox Code Playgroud)

错误:

用户名testø无效,只能包含字母或数字.

我们如何解决它?如何允许一些特殊字符?

c# asp.net-mvc asp.net-identity

2
推荐指数
1
解决办法
1773
查看次数

有时获取ASP.NET MVC5 WebAPI令牌失败

有时获取ASP.NET MVC5 WebAPI令牌失败

string GetAPITokenSync(string username, string password, string apiBaseUri)
        {
            var token = string.Empty;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiBaseUri);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.Timeout = TimeSpan.FromSeconds(60);  

                //setup login data
                var formContent = new FormUrlEncodedContent(new[]
                {
                 new KeyValuePair<string, string>("grant_type", "password"),
                 new KeyValuePair<string, string>("username", username),
                 new KeyValuePair<string, string>("password", password),
                 });

                //send request               
                Task t = Task.Run(() =>
                {
                    HttpResponseMessage responseMessage = client.PostAsync("/Token", formContent).Result;
                    var responseJson = responseMessage.Content.ReadAsStringAsync().Result;
                    var jObject = JObject.Parse(responseJson);
                    token = jObject.GetValue("access_token").ToString();
                }); …
Run Code Online (Sandbox Code Playgroud)

.net c# httpclient token asp.net-mvc-5

2
推荐指数
1
解决办法
7006
查看次数

WebClient DownloadFileAsync() 不起作用

WebClient DownloadFileAsync() 不适用于相同的 URl 和凭据...

有什么线索吗?

 static void Main(string[] args)
        {
            try
            {
                var urlAddress = "http://mywebsite.com/msexceldoc.xlsx";


                using (var client = new WebClient())
                {
                    client.Credentials = new NetworkCredential("UserName", "Password");
                    // It works fine.  
                    client.DownloadFile(urlAddress, @"D:\1.xlsx");
                }

                /*using (var client = new WebClient())
                {
                   client.Credentials = new NetworkCredential("UserName", "Password");

                    // It y creats file with 0 bytes. Dunow why is it. 
                    client.DownloadFileAsync(new Uri(urlAddress), @"D:\1.xlsx");
                    //client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);

                }*/
            }
            catch (Exception ex)
            {

            }
        }
Run Code Online (Sandbox Code Playgroud)

.net c# webclient downloadfileasync

2
推荐指数
1
解决办法
3917
查看次数

如何安排youtube iframe的比例高度

我想为 youtube 链接使用 100% 宽度和比例高度。

但似乎高度得到了不正确的值。

请帮忙

  
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

  
  
  <div data-role="tabs" id="tabs">
        <div data-role="navbar">
            <ul>
                <li><a href="#one" class="ui-btn-active" data-ajax="false">Film</a></li>
                <li><a href="#two" data-ajax="false">Trailer</a></li>
 
            </ul>
        </div>
        <div id="one">
          <br />   
        
            
        </div>
        <div id="two">
            <br />   
            <iframe  style="width:100%; border: none"
                    src="https://www.youtube.com/embed/sR_G6XXZaNI"></iframe>
        </div>
       
    </div>
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

2
推荐指数
1
解决办法
1843
查看次数

如何在拥有类中的`List <T>`中的`T`属性发生更改时实现并触发事件

如何实现与时变化的性质发生触发事件TList<T>所属类别中

我的意思是,不是集合本身,而是属于T.

有什么模式怎么做?

我目前的代码

public class Section
{
    public string Title { get; set; }
    public List<Question> Questions { get; set; } = new List<Question>();

    public int AnsweredQuestion
    {
        get
        {
            return Questions.Count(x => x.State != DeviceNodeTechStateEnum.Undefined);
        }
    }

    public int NonAnsweredQuestion
    {
        get
        {

            return Questions.Count(x => x.State == DeviceNodeTechStateEnum.Undefined);
        }
    }

    public string QuestionStats
    {
        get
        {
            return string.Format("{0}/{1}", AnsweredQuestion, Questions.Count);
        }
    }
}

public class Question : INotifyPropertyChanged
{
    public Guid …
Run Code Online (Sandbox Code Playgroud)

c# collections events

2
推荐指数
1
解决办法
114
查看次数

C#中的Genereic反序列化方法

我有这个方法来序列化任何类型的对象

    public static string SerializeObject<T>(this T toSerialize)
    {
        XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
        StringWriter textWriter = new StringWriter();

        xmlSerializer.Serialize(textWriter, toSerialize);
        return textWriter.ToString();
    }
Run Code Online (Sandbox Code Playgroud)

现在我需要一些方法来将字符串反序列化为对象类型,我可以依赖于某些代码.

我的问题是如何实施这种方法?

感谢你们!

c# serialization xml-serialization deserialization

1
推荐指数
1
解决办法
128
查看次数

通知用户帐户锁定,即在ASP .NET MVC2下

我必须在MVC2项目中为SqlMembershipProvider 实现" Your Account is Locked! "消息.

我怎么能这样做?

基本上我的登录代码如下:

[RequireHttps]
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
      if (ModelState.IsValid)
      {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                     FormsService.SignIn(model.UserName, model.RememberMe);

                     UserProfile profile = UserProfile.GetUserProfile(model.UserName);

                 //.... 
                }
                else
                {
          ModelState.AddModelError("", "The user name or password provided is incorrect.");
        }
   }

   return View(model);
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-membership asp.net-mvc-2

1
推荐指数
1
解决办法
1449
查看次数